/*
 * 文件名： VehicleAllReq.java
 * 
 * 创建日期： 2016年11月24日
 *
 * Copyright(C) 2016, by <a href="mailto:liws@xingyuanauto.com">liws</a>.
 *
 * 原始作者: liws
 *
 */
package com.moli.iov.protocol.model.realtime;

import java.io.Serializable;

import com.moli.iov.protocol.codec.DataEncoder;
import com.moli.iov.protocol.codec.Serialize;
import com.moli.iov.protocol.enums.realtime.ChargeStateTag;
import com.moli.iov.protocol.enums.realtime.DcStateTag;
import com.moli.iov.protocol.enums.realtime.GearStateTag;
import com.moli.iov.protocol.enums.realtime.RunModeTag;
import com.moli.iov.protocol.enums.realtime.VehicleStateTag;
import com.moli.iov.protocol.model.EntityBytesLen;
import com.moli.iov.util.ByteArrayUtil;



/**
 * 整车数据
 *
 * @author <a href="mailto:liws@xingyuanauto.com">liws</a>
 *
 * @version $Revision$
 *
 * @since 2016年11月24日
 */
@Serialize(unit="byte",isBigEndian=true)
public class VehicleAllReq implements Serializable,EntityBytesLen{

	 /** 
	 */ 
	public static final long serialVersionUID = 1L;

	 /**
	 *
	 */
	@Override
	public int getBytesLen() {
		return 20;
	}
	/**
	 * 车辆状态
	 */
	@Serialize(unit="byte",offset=0,size=1)
	public VehicleStateTag vehicleState;
	
	/**
	 * 充电状态
	 */
	@Serialize(unit="byte",offset=1,size=1)
	public ChargeStateTag chargeState;
	
	/**
	 * 运行模式
	 */
	@Serialize(unit="byte",offset=2,size=1)
	public RunModeTag runMode;
	
	/**
	 * 车速
	 */
	@Serialize(unit="byte",offset=3,size=2,min=0,max=2200,coefficient=0.1)
	public double speed;
	
	/**
	 * 累计里程(km)
	 */
	@Serialize(unit="byte",offset=5,size=4,min=0,max=9999999,coefficient=0.1)
	public double odometer;
	
	/**
	 * 总电压(V)
	 */
	@Serialize(unit="byte",offset=9,size=2,min=0,max=10000,coefficient=0.1)
	public double totalVoltage;
	
	/**
	 * 总电流(A)
	 */
	@Serialize(unit="byte",offset=11,size=2,min=0,max=20000,valOffset=1000,coefficient=0.1)
	public double totalCurrent;
	
	/**
	 * 电池电量(1~100) %
	 */
	@Serialize(unit="byte",offset=13,size=1,min=0,max=100)
	public byte soc;
	
	/**
	 * DC-DC状态
	 * 
	 */
	@Serialize(unit="byte",offset=14,size=1)
	public DcStateTag dcStateTag;
	/**
	 * 车辆档位
	 * 
	 */
	@Serialize(unit="byte",offset=15,size=1)
	public GearStateTag gear;
	
	/**
	 * 绝缘电阻(Insulation Resistance)
	 * 
	 * kΩ
	 */
	@Serialize(unit="byte",offset=16,size=2,min=0,max=60000)
	public int insResistance;
	
	/**
	 * 	加速踏板行程值
	 *	有效值范围：0～100(表示0%～100%)；
	 *	最小计量单元：1%；
	 *	"0xFE"表示异常，"0xFF"表示无效。
	 * 
	 */
	@Serialize(unit="byte",offset=18,size=1,min=0,max=100)
	public byte speedUpValue;
	
	/**
	 * 制动踏板行程值
	 * 
	 * 有效值范围：0～100(表示0%～100%)；
	 * 最小计量单元：1%；
	 * “0”表示制动关状态；在无具体形成值情况下，用“0x65”即“101”表示制动有效状态，
	 * "0xFE"表示异常，"0xFF"表示无效。
	 */
	@Serialize(unit="byte",offset=19,size=1,min=0,max=101)
	public byte brakeTravelValue;
	

	public VehicleStateTag getVehicleState() {
		return vehicleState;
	}

	public void setVehicleState(VehicleStateTag vehicleState) {
		this.vehicleState = vehicleState;
	}

	public ChargeStateTag getChargeState() {
		return chargeState;
	}

	public void setChargeState(ChargeStateTag chargeState) {
		this.chargeState = chargeState;
	}

	public RunModeTag getRunMode() {
		return runMode;
	}

	public void setRunMode(RunModeTag runMode) {
		this.runMode = runMode;
	}

	public double getSpeed() {
		return speed;
	}

	public void setSpeed(double speed) {
		this.speed = speed;
	}

	public double getOdometer() {
		return odometer;
	}

	public void setOdometer(double odometer) {
		this.odometer = odometer;
	}

	public double getTotalVoltage() {
		return totalVoltage;
	}

	public double getTotalCurrent() {
		return totalCurrent;
	}

	public void setTotalCurrent(double totalCurrent) {
		this.totalCurrent = totalCurrent;
	}

	public void setTotalVoltage(double totalVoltage) {
		this.totalVoltage = totalVoltage;
	}

	public byte getSoc() {
		return soc;
	}

	public void setSoc(byte soc) {
		this.soc = soc;
	}

	public DcStateTag getDcStateTag() {
		return dcStateTag;
	}

	public void setDcStateTag(DcStateTag dcStateTag) {
		this.dcStateTag = dcStateTag;
	}

	public GearStateTag getGear() {
		return gear;
	}

	public void setGear(GearStateTag gear) {
		this.gear = gear;
	}

	public int getInsResistance() {
		return insResistance;
	}

	public void setInsResistance(int insResistance) {
		this.insResistance = insResistance;
	}
	 
    /**
     * @return the speedUpValue
     */
    public byte getSpeedUpValue() {
        return speedUpValue;
    }
    
    /**
     * @param speedUpValue the speedUpValue to set
     */
    public void setSpeedUpValue(byte speedUpValue) {
        this.speedUpValue = speedUpValue;
    }

    /**
     * @return the brakeTravelValue
     */
    public byte getBrakeTravelValue() {
        return brakeTravelValue;
    }
    
    /**
     * @param brakeTravelValue the brakeTravelValue to set
     */
    public void setBrakeTravelValue(byte brakeTravelValue) {
        this.brakeTravelValue = brakeTravelValue;
    }

    /**
	 *
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("VehicleAllReq [vehicleState=");
		builder.append(vehicleState);
		builder.append(", chargeState=");
		builder.append(chargeState);
		builder.append(", runMode=");
		builder.append(runMode);
		builder.append(", speed=");
		builder.append(speed);
		builder.append(", odometer=");
		builder.append(odometer);
		builder.append(", totalVoltage=");
		builder.append(totalVoltage);
		builder.append(", totalCurrent=");
		builder.append(totalCurrent);
		builder.append(", soc=");
		builder.append(soc);
		builder.append(", dcStateTag=");
		builder.append(dcStateTag);
		builder.append(", gear=");
		builder.append(gear);
		builder.append(", insResistance=");
		builder.append(insResistance);
		builder.append(", speedUpValue=");
		builder.append(speedUpValue);
		builder.append(", brakeTravelValue=");
		builder.append(brakeTravelValue);
		builder.append("]");
		return builder.toString();
	}

	public static void main(String[] args) {
		VehicleAllReq v = new VehicleAllReq();
		v.setVehicleState(VehicleStateTag.STARTING);
		v.setChargeState(ChargeStateTag.TRAVEL_CHARGING);
		v.setRunMode(RunModeTag.EV);
		v.setSpeed(64);
		v.setOdometer(196);
		v.setTotalVoltage((short)20000);
		v.setTotalCurrent((short)12222);
		v.setSoc((byte)56);
		v.setDcStateTag(DcStateTag.WORKING);
		v.setGear(new GearStateTag(GearStateTag.ExistDriveForces.YES,GearStateTag.ExistBraking.YES,GearStateTag.Gears.DRIVE));
		v.setInsResistance((short)1344);
		DataEncoder<VehicleAllReq> vDataEncoder = new DataEncoder<VehicleAllReq>();
		byte[] bytes;
		try {
			bytes = vDataEncoder.encode1(v);
			System.out.println((ByteArrayUtil.toHexString(bytes)));
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//ReportBody<VehicleAllData> vData = new ReportBody<VehicleAllData>(rh, v);
		
	}

}
